const TypesDemo = function(){
  console.log("---TypesDemo----");

  // Symbol 函数可以接受字符串作为参数，表示对 Symbol 实例的描述
  const firstName = Symbol("name");
  const secondName = Symbol("name");
  console.log(typeof firstName,typeof secondName)
  //firstName === secondName


  const sym = Symbol();
  // let obj = {
  //   [sym]: "value",
  // };
  // console.log(obj[sym]); // "value"

  const getClassNameSymbol = Symbol();
  class C {
    [getClassNameSymbol]() {
      return "C";
    }
  }
  let c = new C();
  let className = c[getClassNameSymbol]();
  console.log(className) // "C"

  const list: (string | number)[] = [1,2,'3'];  //[1, 2, "3"]
  const arr: Array<string> = ['a','b']   // ['a','b']
  console.log(list,arr)


  let obj: any = { x: 0 };
  // None of the following lines of code will throw compiler errors.
  // Using `any` disables all further type checking, and it is assumed
  // you know the environment better than TypeScript.
  //obj.foo();
  // obj();
  // obj.bar = 100;
  // obj = "hello";
  // const n: number = obj;


  let myName = "Alice";

  // function Log1(str: string){

  // }
  // function Log2(str: any){

  // }
  // function Log3(str){

  // }

  let uncertain: unknown = 'Hello'!;
  uncertain = 12;
  uncertain = { hello: () => 'Hello!' };

  let uncertain1: unknown = 'Hello'!;
  let notSure: any = uncertain1;


  function getString() {
    return 'helllo world'
  }

  const str: unknown = getString();
  //str.toUpperCase(); // Error: Object is of type 'unknown'
  (str as string).toUpperCase()

  function noReturnFunc(): void{
    console.log("noReturnFunc")
  }

  let uType: undefined = undefined;
  let nType: null = null;

  function doSomething(x: string | undefined) {
    //console.log(x.toUpperCase())  //对象可能为“未定义”。ts(2532)
    console.log(x?.toUpperCase())  //HELLO
    console.log(x!.toUpperCase())  //HELLO
  }
  doSomething(undefined)

  function throwErrror(): never{
    throw new Error("Sorry, get error")
  }

}

export default TypesDemo;
